package com.imooc.bigdata.hos.server.filemgr.service;

import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.FilterList;

import java.util.List;

/**
 * @author liyuhui
 * @date {DATE}
 * @description
 */
public interface IHBaseService {
    /**
     * createTable.
     *
     * @param tableName tableName
     * @param cfs cfs 列族的数组
     * @param splitKeys splitKeys 有些表需要预先分区，这里splitKeys就是分区的键
     * @return success of failed
     */
    boolean createTable(Connection connection, String tableName, String[] cfs, byte[][] splitKeys);

    /**
     * createTable.
     *
     * @param tableName tableName
     * @param cfs cfs 列族的数组
     * @return success of failed
     */
    boolean createTable(Connection connection, String tableName, String[] cfs);

    /**
     * deleteTable.
     *
     * @param tableName tableName
     * @return success of failed
     */

    boolean deleteTable(Connection connection, String tableName);

    /**
     * 删除ColumnFamily.
     */
    boolean deleteColumnFamily(Connection connection,
                               String tableName,
                               String columnFamilyName);

    /**
     * 删除qualifier.
     * //todo 这里为什么需要rowkey？
     */
    boolean deleteColumnQualifier(Connection connection,
                                  String tableName,
                                  String rowKey,
                                  String columnFamilyName,
                                  String qualifierName);

    /**
     * 删除 Qualifier
     */
    boolean deleteColumnQualifier(Connection connection,
                                  String tableName,
                                  Delete delete);

    /**
     * 删除row.
     */
    boolean deleteRow(Connection connection,
                      String tableName,
                      String rowKey,
                      String columnFamilyName,
                      String qualifierName);

    /**
     * 删除row.
     */
    boolean deleteRow(Connection connection,
                      String tableName,
                      Delete delete);

    /**
     * 删除row.
     */
    boolean deleteRow(Connection connection,
                      String tableName,
                      String rowKey);

    /**
     * delete rows.
     *
     * @param tableName tableName
     * @param rows rows
     * @return success of failed
     */

    boolean deleteRows(Connection connection,
                       String tableName,
                       List<String> rows);

    /**
     * existsRow.
     */

    boolean existsRow(Connection connection, String tableName, String row);

    /**
     * getRow.
     */

    Result getRow(Connection connection,
                  String tableName,
                  String row,
                  FilterList filterList);

    /**
     * getRow.
     */

    Result getRow(Connection connection,
                  String tableName,
                  Get get);

    /**
     * getRow.
     */
    Result getRow(Connection connection,
                  String tableName,
                  String rowKey);

    /**
     * getRow.
     */

    Result getRow(Connection connection,
                  String tableName,
                  String row,
                  byte[] column,
                  byte[] qualifier);

    /**
     * getRows.
     *
     * @param tableName tableName
     * @param rows rows
     * @param filterList filterList
     * @return Result
     */

    Result[] getRows(Connection connection,
                     String tableName,
                     List<String> rows,
                     FilterList filterList);

    /**
     * getRows.
     *
     * @param tableName tableName
     * @param rows rows
     * @return Result
     */

    Result[] getRows(Connection connection,
                     String tableName,
                     List<String> rows);

    /**
     * 生成目录的seqid
     * @param connection
     * @param tableName
     * @param row
     * @param columnFamily
     * @param qualifier
     * @param num
     * @return
     */
    long incrementColumnValue(Connection connection,
                              String tableName,
                              String row,
                              byte[] columnFamily,
                              byte[] qualifier,
                              int num);

    /**
     * putRow.
     */
    boolean putRow(Connection connection,
                   String tableName,
                   String row,
                   String columnFamily,
                   String qualifier,
                   String data);

    boolean putRow(Connection connection, String tableName, Put put);

    /**
     * put rows
     */
    boolean putRow(Connection connection, String tableName, List<Put> puts);

    /**
     * 扫描整张表，记得释放rs.
     */
    ResultScanner scanner(Connection connection, String tableName);

    /**
     * scanner.
     */
    ResultScanner scanner(Connection connection,
                          String tableName,
                          String startRowKey,
                          String stopRowKey);

    /**
     * scanner.
     */
    ResultScanner scanner(Connection connection,
                          String tableName,
                          byte[] startRowKey,
                          byte[] stopRowKey);

    /**
     * scanner.
     */
    ResultScanner scanner(Connection connection,
                          String tableName,
                          FilterList filterList);

    /**
     * scanner.
     */
    ResultScanner scanner(Connection connection,
                          String tableName,
                          Scan scan);

    /**
     * scanner.
     */
    ResultScanner scanner(Connection connection,
                          String tableName,
                          byte[] startRowKey,
                          byte[] stopRowKey,
                          FilterList filterList);

    /**
     * scanner.
     */
    ResultScanner scanner(Connection connection,
                          String tableName,
                          String startRowKey,
                          String stopRowKey,
                          FilterList filterList);
}
